<?php
	require_once("utils.php");
	require_once("obj/project.php");
	$projectId = $_GET["projectId"];
	$project = Project::getByProjectId($projectId);
	if(isset($_POST["btnSubmit"])){ 
		if($_POST["btnSubmit"] == "Save") {
			$project->Name = $_POST["txtName"];
			$project->Description = $_POST["txtDescription"];
			$project->save();
		}
		else if($_POST["btnSubmit"] == "Delete") { 
			$project->delete();
		}
		
		$err = error_get_last();
		if (empty($err)) {
			$u = Utils::makeProjectsUrl();
			header("Location:$u");
		}
	}
?>

<form method="post" action="<?php echo Utils::makeProjectDetailUrl($projectId);?>">
	<table cellpadding="5" cellspacing="0" border="0">
		<tr>
			<td>Name:</td>
			<td><input type="text" name="txtName" id="txtName" value="<?php echo $project->Name; ?>" /></td>
		</tr>
		<tr>
			<td valign="top">Description:</td>
			<td>
				<textarea name="txtDescription" id="txtDescription"><?php echo $project->Description; ?></textarea>
			</td>
		</tr>
		<tr>
			<td colspan="2">
				<input name="btnSubmit" type="submit" value="Save" />
				<input name="btnSubmit" type="submit" value="Delete" />
				<input type="button" value="Cancel" onclick="javascript:history.back();" />
			</td>
		</tr>
	</table>
</form>
